<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"/>




  <link href="//fonts.googleapis.com/css?family=Lato:300,400,700,400italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">



<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=0.5.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="C++教程," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=0.5.0" />






<meta name="description" content="##说明 
我们使用的是C++语言,C++语言是对C语言的拓展,主要加上的是面对对象的部分,它的输出的风格是cin和cout.C++语言为了保持对C语言的兼容,同时也有C风格的的输入输出scanf,printf.
在具体的学习中,我是更倾向使用scanf,printf,这里的原因和风格有一定关系,但是最重要的是:在以完成题目的为前提下,选一个简单的来用,keep it simple and stu">
<meta property="og:type" content="article">
<meta property="og:title" content="C++输入输出讲解">
<meta property="og:url" content="http://yoursite.com/2016/03/cpp输入输出讲解/index.html">
<meta property="og:site_name" content="Rainboy">
<meta property="og:description" content="##说明 
我们使用的是C++语言,C++语言是对C语言的拓展,主要加上的是面对对象的部分,它的输出的风格是cin和cout.C++语言为了保持对C语言的兼容,同时也有C风格的的输入输出scanf,printf.
在具体的学习中,我是更倾向使用scanf,printf,这里的原因和风格有一定关系,但是最重要的是:在以完成题目的为前提下,选一个简单的来用,keep it simple and stu">
<meta property="og:updated_time" content="2016-03-27T00:53:15.423Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="C++输入输出讲解">
<meta name="twitter:description" content="##说明 
我们使用的是C++语言,C++语言是对C语言的拓展,主要加上的是面对对象的部分,它的输出的风格是cin和cout.C++语言为了保持对C语言的兼容,同时也有C风格的的输入输出scanf,printf.
在具体的学习中,我是更倾向使用scanf,printf,这里的原因和风格有一定关系,但是最重要的是:在以完成题目的为前提下,选一个简单的来用,keep it simple and stu">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"hide"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: 'Author'
    }
  };
</script>

  <title> C++输入输出讲解 | Rainboy </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh_Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Rainboy</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle"></p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-home fa-fw"></i> <br />
            
            Startseite
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-th fa-fw"></i> <br />
            
            Kategorien
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-archive fa-fw"></i> <br />
            
            Archiv
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-tags fa-fw"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                C++输入输出讲解
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Veröffentlicht am</span>
            <time itemprop="dateCreated" datetime="2016-03-27T08:37:00+08:00" content="2016-03-27">
              2016-03-27
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">in</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/课件/" itemprop="url" rel="index">
                    <span itemprop="name">课件</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/03/cpp输入输出讲解/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/03/cpp输入输出讲解/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>##说明 </p>
<p>我们使用的是C++语言,C++语言是对C语言的拓展,主要加上的是面对对象的部分,它的输出的风格是<code>cin</code>和<code>cout</code>.C++语言为了保持对C语言的兼容,同时也有C风格的的输入输出<code>scanf</code>,<code>printf</code>.</p>
<p>在具体的学习中,我是更倾向使用<code>scanf</code>,<code>printf</code>,这里的原因和风格有一定关系,但是最重要的是:<strong>在以完成题目的为前提下,选一个简单的来用,keep it simple and stupid</strong></p>
<p>下面我会把这两种风格都说一下:</p>
<h2 id="C-中C风格的的输入输出"><a href="#C-中C风格的的输入输出" class="headerlink" title="C++中C风格的的输入输出"></a>C++中C风格的的输入输出</h2><h3 id="先来一点预备知识"><a href="#先来一点预备知识" class="headerlink" title="先来一点预备知识"></a>先来一点预备知识</h3><p>前面的学习我们已经知道<code>`A` </code>,这样被单引号括表示的是字符,<code>&quot;hello world&quot;</code>这样被又引号括起来是是字符串,所谓的<code>字符串</code>就是<code>字符</code>的组合,这样可以产生一些有意义的语句了.</p>
<p>我们平常写的代码,想要输出的东西就是一串字符,输出到console上(就是那个黑色的框框).那我们怎么用C风格来输出呢?</p>
<pre><code>printf(&quot;hello word!&quot;);
</code></pre><p>当然我们要引入C风格头文件<code>#include &lt;cstdio&gt;</code>.上面的是最简单的输出,不好的地方就是每一次的输出都一样,如果我们想要让输出按我们的意思输出怎么办?比较输出<code>int a=10;</code>这种变量的值怎么办?</p>
<h3 id="C风格-格式化输出-printf"><a href="#C风格-格式化输出-printf" class="headerlink" title="C风格 格式化输出 printf"></a>C风格 格式化输出 printf</h3><p>printf调用:</p>
<center> ** printf(“格式化字符串”,参数表)</center>

<p>格式化字符:</p>
<center>%[标志][输出最小宽度][.精度][长度]格式化字符</center>

<p>更标准一点的说法:</p>
<center>%[flags][width][.prec][F|N|h|i]type</center>


<p>简单的例子:</p>
<pre><code>printf(&quot;%1.2f&quot;,11.11111)
</code></pre><p>得到的答案是<code>1.11</code>,因为我们规定了输出的width是1,prec是2,那余的东西就会被丢掉.下面看表格:</p>
<table>
<thead>
<tr>
<th>flags</th>
<th>名称</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>-</td>
<td>左对齐</td>
<td>右边填充空格(默认右对齐)</td>
</tr>
<tr>
<td>+</td>
<td>加号</td>
<td>在数字前增加符号 + 或 -</td>
</tr>
<tr>
<td>0</td>
<td>数字零</td>
<td>将输出的前面补上0，直到占满指定列宽为止（不可以搭配使用“-”）</td>
</tr>
<tr>
<td>　</td>
<td>空格</td>
<td>输出值为正时加上空格，为负时加上负号</td>
</tr>
<tr>
<td>#</td>
<td>井号</td>
<td>type是o、x、X时，增加前缀0、0x、0X,type是e、E、f、g、G时，一定使用小数点,type是g、G时，尾部的0保留</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>type</th>
<th>对应的数据类型</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>d</td>
<td>int</td>
<td>接受整数值并将它表示为有符号的十进制整数</td>
</tr>
<tr>
<td>lld</td>
<td>long long</td>
<td>同上,但是表示64bit的long long</td>
</tr>
<tr>
<td>x</td>
<td>unsiged int</td>
<td>小写16进制</td>
</tr>
<tr>
<td>X</td>
<td>unsiged int</td>
<td>大写16进制</td>
</tr>
<tr>
<td>o</td>
<td>unsiged int</td>
<td>8进制</td>
</tr>
<tr>
<td>u</td>
<td>unsiged int</td>
<td>无符号10进制</td>
</tr>
<tr>
<td>f</td>
<td>float</td>
<td>单精度浮点数</td>
</tr>
<tr>
<td>lf</td>
<td>double</td>
<td>双精度浮点数</td>
</tr>
<tr>
<td>s</td>
<td>char *</td>
<td>字符串</td>
</tr>
</tbody>
</table>
<p>width:<br>是一个可选的指定最小值字段宽度的十进制数字字符串。如果转换值字符少于字段宽度，该字段将从左到右按指定的字段宽度填充。如果指定了左边调整选项，字段将在右边填充。如果转换结果宽于字段宽度，将扩展该字段以包含转换后的结果。不会发生截断。然而，小的精度可能导致在右边发生截断。</p>
<p>prec:<br>用于控制小数点后面的位数，取值和含义如下：缺省精度0,其它精度n(1,2,3,4…)</p>
<table>
<thead>
<tr>
<th>转义字符</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td>\n</td>
<td>换行</td>
</tr>
<tr>
<td>\</td>
<td>一个\</td>
</tr>
<tr>
<td>\’</td>
<td>一个’</td>
</tr>
<tr>
<td>\”</td>
<td>一个”</td>
</tr>
<tr>
<td>\xhh</td>
<td>hh二位的16进制所代表的字符</td>
</tr>
</tbody>
</table>
<blockquote>
<p><strong>注意:</strong> 上面说了那么多,是不是都要记住,不要,我们只要知道有这些东西就行了,具休只要下面的代码有看懂就行</p>
</blockquote>
<h4 id="代码举例"><a href="#代码举例" class="headerlink" title="代码举例"></a>代码举例</h4><pre><code>#include &lt;cstdio&gt;
int main(){
    double a=1123.123456;
    int b =12;
    printf(&quot;%6.2f\n&quot;,a);
    printf(&quot;%d\n&quot;,b);
    printf(&quot;%4d\n&quot;,b);
    printf(&quot;%-4d\n&quot;,b);
    printf(&quot;%04d\n&quot;,b);
    printf(&quot;%4.4d\n&quot;,b);
    printf(&quot;my favrite num is :%d\n&quot;,9);
    printf(&quot;%03d %c,%f hh %s&quot;,12,&#39;A&#39;,1.1,&quot;RAINBOY&quot;);
    return 0;
}
</code></pre><p>结果是</p>
<pre><code>1123.12
12
  12
12
0012
0012
my favrite num is :9
012 A,1.100000 hh RAINBOY
</code></pre><h3 id="scanf-的使用"><a href="#scanf-的使用" class="headerlink" title="scanf 的使用"></a>scanf 的使用</h3><p> scanf() 是从标准输入流stdio (标准输入设备，一般是键盘)中读内容的通用子程序，可以说明的格式读入多个字符，并保存在对应地址的变量中。[</p>
<p> 调用方式:</p>
<center>scanf(“参数表”,变量地址)</center>

<p> 简单的来说就是从console里读取,下面几个问题我们要知道:</p>
<ul>
<li>%d读取的时候会把不可见的字符略去</li>
<li>你在console输入数据的时候,按下回车的时候,才把数据提交</li>
<li>定 %d%d%d 之间最好不要有其它东西</li>
</ul>
<h4 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h4><pre><code>#include&lt;stdio&gt;
int main(void)
{
int a,b,c;
printf(&quot;输入a,b,c\n&quot;);
scanf(&quot;%d%d%d&quot;,&amp;a,&amp;b,&amp;c);
printf(&quot;a=%d,b=%d,c=%d\n&quot;,a,b,c);
return 0;
}
</code></pre><p>基本会写上面的这个代码就会能写90%以上的题目了,如果在写题目真的遇到了怎么办?看这个<a href="http://baike.baidu.com/link?url=1f3edcVHlc0ey2QsxEHi9zDDB8HwwYWmXMUgP0HZM1CDDE-PD5Yr8mUV5dTDlJAI8kaiu2hDHACfLOh3avWQS_" target="_blank" rel="external">百度百科</a></p>
<p>下面的这些要撑握:</p>
<p>1.读取到文件地末尾:</p>
<p>2.读取一行字符:</p>
<p>3.读取一行数字:</p>
<h2 id="cin-cout-的使用"><a href="#cin-cout-的使用" class="headerlink" title="cin cout 的使用"></a>cin cout 的使用</h2><p>要包含头文件:<code>&lt;iostream&gt;</code>,要写这句话:<code>using namespace std;</code></p>
<p>cout语句的一般格式为：<code>cout&lt;&lt;表达式1&lt;&lt;表达式2&lt;&lt;……&lt;&lt;表达式n;</code></p>
<p>cin语句的一般格式为：<code>cin&gt;&gt;变量1&gt;&gt;变量2&gt;&gt;……&gt;&gt;变量n;</code></p>
<p>这里说一下对理解:把cout想像成cout 想象成console, <code>&lt;&lt;</code>表示一个流向,会把数据流向cout,而cout就是console,现时<code>&lt;&lt;</code>操作完后会返回cout,所以可以写成一个长链,cin同理,只不过把cin当成键盘.</p>
<p>与printf相比,如果我想输出一行话,只要写一个长链串起来就可以了.</p>
<pre><code>cout &lt;&lt; &quot;hello word&quot; &lt;&lt; 10 &lt;&lt; &#39; &#39; &lt;&lt; endl;
</code></pre><h3 id="cin-cout-控制符"><a href="#cin-cout-控制符" class="headerlink" title="cin cout 控制符"></a>cin cout 控制符</h3><p><code>#include &lt;iomanip&gt;</code></p>
<table>
<thead>
<tr>
<th>cout 控制</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>dec</td>
<td>%d</td>
</tr>
<tr>
<td>hex</td>
<td>%x</td>
</tr>
<tr>
<td>oct</td>
<td>%o</td>
</tr>
<tr>
<td>setfill(‘c’)</td>
<td>填充字符为c</td>
</tr>
<tr>
<td>setw(n)</td>
<td>宽度为n</td>
</tr>
<tr>
<td>setprecision(b)</td>
<td>浮点数小数部分长度为n</td>
</tr>
</tbody>
</table>
<h4 id="代码-1"><a href="#代码-1" class="headerlink" title="代码"></a>代码</h4><pre><code>/*一个按进制输出的例子*/

#include&lt;iostream.h&gt;

void main()

{

int x=30, y=300, z=1024;

cout&lt;&lt;x&lt;&lt;&#39; &#39;&lt;&lt;y&lt;&lt;&#39; &#39;&lt;&lt;z&lt;&lt;endl; //按十进制输出

cout.unsetf(ios::dec ); //取消十进制输出设置

cout.setf(ios::showbase | ios::uppercase); //设置基指示符输出和数值中的字母大写输出

cout&lt;&lt;x&lt;&lt;&#39; &#39;&lt;&lt;y&lt;&lt;&#39; &#39;&lt;&lt;z&lt;&lt;endl;

cout.unsetf(ios::showbase | ios::uppercase); //取消基指示符输出和数值中的字母大写输出

cout.setf(ios::oct); //设置为八进制输出,此设置不取消一直有效

cout&lt;&lt;x&lt;&lt;&#39; &#39;&lt;&lt;y&lt;&lt;&#39; &#39;&lt;&lt;z&lt;&lt;endl; //按八进制输出

cout.setf(ios::showbase | ios::uppercase); //设置基指示符输出和数值中的字母大写输出

cout&lt;&lt;x&lt;&lt;&#39; &#39;&lt;&lt;y&lt;&lt;&#39; &#39;&lt;&lt;z&lt;&lt;endl;

cout.unsetf(ios::showbase | ios::uppercase); //取消基指示符输出和数值中的字母大写输出

cout.unsetf(ios::oct); //取消八进制输出设置，恢复按十进制输出

cout.setf(ios::hex); //设置为十六进制输出

cout&lt;&lt;x&lt;&lt;&#39; &#39;&lt;&lt;y&lt;&lt;&#39; &#39;&lt;&lt;z&lt;&lt;endl;

cout.setf(ios::showbase | ios::uppercase); //设置基指示符输出和数值中的字母大写输出

cout&lt;&lt;x&lt;&lt;&#39; &#39;&lt;&lt;y&lt;&lt;&#39; &#39;&lt;&lt;z&lt;&lt;endl;

cout.unsetf(ios::showbase | ios::uppercase); //取消基指示符输出和数值中的字母大写输出

cout.unsetf(ios::hex); //取消十六进制输出设置，恢复按十进制输出

cout&lt;&lt;x&lt;&lt;&#39; &#39;&lt;&lt;y&lt;&lt;&#39; &#39;&lt;&lt;z&lt;&lt;endl;

}
</code></pre><p>##FAQ:算法竞赛的时候用cin cout输入输出比用scanf printf慢多少？</p>
<ul>
<li><a href="https://www.zhihu.com/question/27831271/answer/38379464" target="_blank" rel="external">https://www.zhihu.com/question/27831271/answer/38379464</a></li>
<li><a href="https://www.byvoid.com/blog/fast-readfile" target="_blank" rel="external">https://www.byvoid.com/blog/fast-readfile</a></li>
</ul>
<h2 id="要善用网络"><a href="#要善用网络" class="headerlink" title="要善用网络"></a>要善用网络</h2>
      
    </div>

    <div>
      
        
      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/C-教程/" rel="tag">#C++教程</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/03/二进制优化原理/" rel="next" title="二进制优化原理">
                <i class="fa fa-chevron-left"></i> 二进制优化原理
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/03/git学习笔记/" rel="prev" title="git学习笔记">
                git学习笔记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2016/03/cpp输入输出讲解/"
           data-title="C++输入输出讲解" data-url="http://yoursite.com/2016/03/cpp输入输出讲解/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Inhaltsverzeichnis
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Übersicht
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.jpg"
               alt="Rainboy" />
          <p class="site-author-name" itemprop="name">Rainboy</p>
          <p class="site-description motion-element" itemprop="description">Rainboy Personal Blog by Hexo</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">16</span>
              <span class="site-state-item-name">Artikel</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">Kategorien</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">23</span>
                <span class="site-state-item-name">Tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        <div class="links-of-blogroll motion-element">
          
        </div>

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc-indicator-top post-toc-indicator">
            <i class="fa fa-angle-double-up"></i>
          </div>
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#C-中C风格的的输入输出"><span class="nav-number">1.</span> <span class="nav-text">C++中C风格的的输入输出</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#先来一点预备知识"><span class="nav-number">1.1.</span> <span class="nav-text">先来一点预备知识</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#C风格-格式化输出-printf"><span class="nav-number">1.2.</span> <span class="nav-text">C风格 格式化输出 printf</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#代码举例"><span class="nav-number">1.2.1.</span> <span class="nav-text">代码举例</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#scanf-的使用"><span class="nav-number">1.3.</span> <span class="nav-text">scanf 的使用</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#代码"><span class="nav-number">1.3.1.</span> <span class="nav-text">代码</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#cin-cout-的使用"><span class="nav-number">2.</span> <span class="nav-text">cin cout 的使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#cin-cout-控制符"><span class="nav-number">2.1.</span> <span class="nav-text">cin cout 控制符</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#代码-1"><span class="nav-number">2.1.1.</span> <span class="nav-text">代码</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#要善用网络"><span class="nav-number">3.</span> <span class="nav-text">要善用网络</span></a></li></ol></div>
            
          </div>
          <div class="post-toc-indicator-bottom post-toc-indicator">
            <i class="fa fa-angle-double-down"></i>
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Rainboy</span>
</div>

<div class="powered-by">
  Erstellt mit  <a class="theme-link" href="http://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>



      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  


  




<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>

  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=0.5.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=0.5.0"></script>



  
  

  
  
<script type="text/javascript" src="/js/src/scrollspy.js?v=0.5.0"></script>

<script type="text/javascript" id="sidebar.toc.highlight">
  $(document).ready(function () {
    var tocSelector = '.post-toc';
    var $tocSelector = $(tocSelector);
    var activeCurrentSelector = '.active-current';

    $tocSelector
      .on('activate.bs.scrollspy', function () {
        var $currentActiveElement = $(tocSelector + ' .active').last();

        removeCurrentActiveClass();
        $currentActiveElement.addClass('active-current');

        $tocSelector[0].scrollTop = $currentActiveElement.position().top;
      })
      .on('clear.bs.scrollspy', function () {
        removeCurrentActiveClass();
      });

    function removeCurrentActiveClass () {
      $(tocSelector + ' ' + activeCurrentSelector)
        .removeClass(activeCurrentSelector.substring(1));
    }

    function processTOC () {
      getTOCMaxHeight();
      toggleTOCOverflowIndicators();
    }

    function getTOCMaxHeight () {
      var height = $('.sidebar').height() -
                   $tocSelector.position().top -
                   $('.post-toc-indicator-bottom').height();

      $tocSelector.css('height', height);

      return height;
    }

    function toggleTOCOverflowIndicators () {
      tocOverflowIndicator(
        '.post-toc-indicator-top',
        $tocSelector.scrollTop() > 0 ? 'show' : 'hide'
      );

      tocOverflowIndicator(
        '.post-toc-indicator-bottom',
        $tocSelector.scrollTop() >= $tocSelector.find('ol').height() - $tocSelector.height() ? 'hide' : 'show'
      )
    }

    $(document).on('sidebar.motion.complete', function () {
      processTOC();
    });

    $('body').scrollspy({ target: tocSelector });
    $(window).on('resize', function () {
      if ( $('.sidebar').hasClass('sidebar-active') ) {
        processTOC();
      }
    });

    onScroll($tocSelector);

    function onScroll (element) {
      element.on('mousewheel DOMMouseScroll', function (event) {
          var oe = event.originalEvent;
          var delta = oe.wheelDelta || -oe.detail;

          this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
          event.preventDefault();

          toggleTOCOverflowIndicators();
      });
    }

    function tocOverflowIndicator (indicator, action) {
      var $indicator = $(indicator);
      var opacity = action === 'show' ? 1 : 0;
      $indicator.velocity ?
        $indicator.velocity('stop').velocity({
          opacity: opacity
        }, { duration: 100 }) :
        $indicator.stop().animate({
          opacity: opacity
        }, 100);
    }

  });
</script>

<script type="text/javascript" id="sidebar.nav">
  $(document).ready(function () {
    var html = $('html');
    var TAB_ANIMATE_DURATION = 200;
    var hasVelocity = $.isFunction(html.velocity);

    $('.sidebar-nav li').on('click', function () {
      var item = $(this);
      var activeTabClassName = 'sidebar-nav-active';
      var activePanelClassName = 'sidebar-panel-active';
      if (item.hasClass(activeTabClassName)) {
        return;
      }

      var currentTarget = $('.' + activePanelClassName);
      var target = $('.' + item.data('target'));

      hasVelocity ?
        currentTarget.velocity('transition.slideUpOut', TAB_ANIMATE_DURATION, function () {
          target
            .velocity('stop')
            .velocity('transition.slideDownIn', TAB_ANIMATE_DURATION)
            .addClass(activePanelClassName);
        }) :
        currentTarget.animate({ opacity: 0 }, TAB_ANIMATE_DURATION, function () {
          currentTarget.hide();
          target
            .stop()
            .css({'opacity': 0, 'display': 'block'})
            .animate({ opacity: 1 }, TAB_ANIMATE_DURATION, function () {
              currentTarget.removeClass(activePanelClassName);
              target.addClass(activePanelClassName);
            });
        });

      item.siblings().removeClass(activeTabClassName);
      item.addClass(activeTabClassName);
    });

    $('.post-toc a').on('click', function (e) {
      e.preventDefault();
      var targetSelector = NexT.utils.escapeSelector(this.getAttribute('href'));
      var offset = $(targetSelector).offset().top;
      hasVelocity ?
        html.velocity('stop').velocity('scroll', {
          offset: offset  + 'px',
          mobileHA: false
        }) :
        $('html, body').stop().animate({
          scrollTop: offset
        }, 500);
    });

    // Expand sidebar on post detail page by default, when post has a toc.
    NexT.motion.middleWares.sidebar = function () {
      var $tocContent = $('.post-toc-content');

      if (CONFIG.sidebar.display === 'post' || CONFIG.sidebar.display === 'always') {
        if ($tocContent.length > 0 && $tocContent.html().trim().length > 0) {
          NexT.utils.displaySidebar();
        }
      }
    };
  });
</script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=0.5.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"rainboy"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
  





  
  
  
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
  </script>

  <script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for (i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  </script>

  
    <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

</body>
</html>
